package blue.datacenter;

import blue.platform.ServerInterface;
import blue.logger.Publisher;

public class DataCenter extends Thread implements ServerInterface{
	// TODO 
	ConnManager conn_manager_;
	Publisher pub_;
	
	public DataCenter() {
		//TODO FIX ME: Redundancy code, You can fix me by a list.
		try {
			String pub_port_ = "10001";
			pub_ = new Publisher(pub_port_);
			conn_manager_ = new ConnManager(pub_);
			// Add Connection for Machine
			String uut1_ip = "169.254.1.30";
			String uut2_ip = "169.254.1.31";
			Integer arm_port = 7600;
			Integer power_port = 8082;
			Integer dut_port = 8081;
			Integer master_server_port = 11001;

			MasterServer master_server = new MasterServer(master_server_port);
//			MachineConn uut1_arm_conn = new MachineConn(uut1_ip,arm_port);
			MachineConn uut1_power_conn = new MachineConn(uut1_ip,power_port);
//			MachineConn uut1_dut_conn = new MachineConn(uut1_ip,dut_port);
//			MachineConn uut2_arm_conn = new MachineConn(uut2_ip,arm_port);
//			MachineConn uut2_power_conn = new MachineConn(uut2_ip,power_port);
//			MachineConn uut2_dut_conn = new MachineConn(uut2_ip,dut_port);
			// 
			conn_manager_.addServerConn(master_server);
//			conn_manager_.addMachineConn(uut1_arm_conn);
			conn_manager_.addMachineConn(uut1_power_conn);
//			conn_manager_.addMachineConn(uut1_dut_conn);
//			conn_manager_.addMachineConn(uut2_arm_conn);
//			conn_manager_.addMachineConn(uut2_power_conn);
//			conn_manager_.addMachineConn(uut2_dut_conn);
			// Create Alias-IP, TM will connect to it.
			//...uut1_ip
			//...uut2_ip
		}catch(Exception e){
			// Be careful: For technical reason, you must connection to fixture before create alias-IP.
			System.out.println("Launch DataCenter failed. Please ensure your fixture address is available.");
			e.printStackTrace();
			System.exit(-1);
		}
	}
	
	@Override
	public void start_server() {
		this.start();
	}
	
	@Override
	public void run() {
		conn_manager_.run();
	}
}
